var sharedData=require("dataMgr");
//处理音效播放的节点脚本
cc.Class({
    extends: cc.Component,

    properties: {
        hit: {
            url: cc.AudioClip,
            default: null
        },
        broken: {
            url: cc.AudioClip,
            default: null
        },
        collect: {
            url: cc.AudioClip,
            default: null
        },
        dead: {
            url: cc.AudioClip,
            default: null
        }
    },

    playHit: function () {
        if(!sharedData.isPlaySound){
            return;
        }
        var now=new Date().getTime();
        if(now-this._lastPlayHit<100){
            return;
        }
        cc.audioEngine.play(this.hit,false,1);
        this._lastPlayHit=now;
    },
    playBroken: function () {
        if(!sharedData.isPlaySound){
            return;
        }
        var now=new Date().getTime();
        //100毫秒内只能播放一次声音
        if(now-this._lastPlayBroken<100){
            return;
        }
        cc.audioEngine.play(this.broken,false,1);
        this._lastPlayBroken=now;
    },
    playCollect: function () {
        if(!sharedData.isPlaySound){
            return;
        }
        var now=new Date().getTime();
        if(now-this._lastPlayCollect<100){
            return;
        }
        cc.audioEngine.play(this.collect,false,1);
        this._lastPlayCollect=now;
    },
    playDead: function () {
        if(!sharedData.isPlaySound){
            return;
        }
        var now=new Date().getTime();
        if(now-this._lastPlayDead<100){
            return;
        }
        cc.audioEngine.play(this.dead,false,1);
        this._lastPlayDead=now;
    },
    // LIFE-CYCLE CALLBACKS:
    onLoad() {
        this._lastPlayHit=0;
        this._lastPlayBroken=0;
        this._lastPlayCollect=0;
        this._lastPlayDead=0;
    },
    start() {

    },

    // update (dt) {},
});
